package com.huangliusong;

import com.huangliusong.entity.Goods;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Map;

@Controller
public class AnootationHandler {
    /**
     * 业务方法
     * 完成数据的传递 以及视图的解析
     */
    @RequestMapping("/modelAndViewTest")
    public ModelAndView modelAndViewTest(){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("name","huangliusong");
        modelAndView.setViewName("show");
        return modelAndView;
    }


    @RequestMapping("/ModelTest")
    public String ModelTest(Model model){
        model.addAttribute("name","hls");
        return "show";
    }
    @RequestMapping("/MapTest")
    public  String MapTest(Map<String,String> map){
        map.put("name","huang");
        //设置逻辑视图
        return "show";
    }


    /**
     * 添加商品并且展示
     */
    @RequestMapping("/addGoods")
    public ModelAndView  addGoods(Goods goods){
        System.out.println(goods);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("show");
        modelAndView.addObject("goods",goods);
        return modelAndView;
    }
}
